package com.czh.gzskzn.shenke3.Activity.ShuiFeiActivity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czh.gzskzn.shenke3.Activity.UtilServer.WanZhi;
import com.czh.gzskzn.shenke3.Activity.UtilT.XqUtil;
import com.czh.gzskzn.shenke3.R;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by gzsk on 2017/5/5.
 * name  陈忠红
 * email czhhx15599109256@163.com
 */

public class SfxqActivity extends AppCompatActivity {

    private LinearLayout Back;
    private ImageView imageView;
    private String Hao;

    private TextView jinE,bian,name,riqi,yufen,sdw,bdw,byyl;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sfxq_activity);

        intiVew();

        //新页面接收数据
        Bundle bundle = this.getIntent().getExtras();
        //接收name值
        Hao = bundle.getString("yonhuhao");

        OkGo.get(WanZhi.SHUIFEICHAXUN+Hao)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {

                        Log.e("JSON",s);

                        Gson gson = new Gson();
                        XqUtil xqUtil = gson.fromJson(s,XqUtil.class);
                        name.setText(xqUtil.getUSERNAME());
                        bian.setText(xqUtil.getUSERID());

                        jinE.setText(xqUtil.getJE());
                        List<XqUtil.DATAMXBean> yu = xqUtil.getDATAMX();
                        riqi.setText(yu.get(0).getCBRQ());
                        sdw.setText(yu.get(0).getSYDS());
                        bdw.setText(yu.get(0).getBYDS());
                        byyl.setText(yu.get(0).getBYYL());
                        yufen.setText(yu.get(0).getSMON());


//                        try {
//                            JSONObject jsonObject = new JSONObject(s);
//
//                            String a = jsonObject.getString("image");
//                            //InputStream in_withcode   =   new ByteArrayInputStream(a.getBytes("UTF-8"));
//                            //Bitmap pic = BitmapFactory.decodeStream(a.getBytes("UTF-8"));
//                            byte[] b = a.getBytes("UTF-8");
//                            int size = b.length;
//                            Bitmap pic = BitmapFactory.decodeByteArray(b,0,size);
//                                imageView.setImageBitmap(pic);
//
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        } catch (UnsupportedEncodingException e) {
//                            e.printStackTrace();
//                        }

                    }
                });
        Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
}

private void intiVew() {
        Back = (LinearLayout) findViewById(R.id.ll_sfxq_baike);
        imageView = (ImageView) findViewById(R.id.sf_img);

        jinE = (TextView) findViewById(R.id.tv_xq_yinjiao);
        bian = (TextView) findViewById(R.id.tv_xq_bianhao);
        name = (TextView) findViewById(R.id.tv_xq_name);
        riqi = (TextView) findViewById(R.id.tv_xq_riqi);
        yufen = (TextView) findViewById(R.id.tv_xq_yuefen);
        sdw = (TextView) findViewById(R.id.tv_xq_sdunwei);
        bdw = (TextView) findViewById(R.id.tv_xq_bydw);
        byyl = (TextView) findViewById(R.id.tv_xq_byyl);


}
}
